<?php

namespace app\api\model;

use think\Model;
/**
 * 评论
 */
class CommentModel extends Model
{
    // 表名
    protected $name = 'comment';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    // 追加属性
    protected $append = [
        'time_describe'
    ];

    public function getTimeDescribeAttr($value, $data)
    {
        $time = $data['createtime'] ? tranTime($data['createtime']) : '';
        return $time;
    }

    public function son()
    {
        return $this->hasMany('CommentModel', 'top_id', 'id')->field('id,to_id,top_id,shop_id,relation_id,reply_type,to_reply_type,to_reply_id,reply_id,content,createtime');
    }

}
